import pandas as pd
import numpy as np

AF_data_frame=pd.read_excel('RR_seg_AF.xls',sheet_name='Sheet1')
nonAF_data_frame=pd.read_excel('RR_seg_nonAF.xls',sheet_name='Sheet1')

#np格式
AF_data=AF_data_frame.to_numpy()
nonAF_data=nonAF_data_frame.to_numpy()
print(AF_data.shape,nonAF_data.shape)

#准备一个行数相同的矩阵
import math
m=10
AF_input=np.empty([AF_data.shape[0],10])


AF_input[:,0]=np.mean(AF_data,axis=1)
AF_input[:,1]=np.median(AF_data,axis=1)
AF_input[:,2]=np.amin(AF_data,axis=1)
AF_input[:,3]=np.amax(AF_data,axis=1)
AF_input[:,4]=np.ptp(AF_data,axis=1)
AF_input[:,5]=np.std(AF_data,axis=1)
AF_input[:,6]=np.var(AF_data,axis=1)
AF_input[:,7]=np.log(2*math.pi*math.e*np.var(AF_data,axis=1))
AF_input[:,8]=pd.DataFrame.skew(AF_data_frame,axis=1)
AF_input[:,9]=pd.DataFrame.kurt(AF_data_frame,axis=1)
print(AF_input.shape)

#同理
nonAF_input=np.empty([nonAF_data.shape[0],m])
nonAF_input[:,0]=np.mean(nonAF_data,axis=1)
nonAF_input[:,1]=np.median(nonAF_data,axis=1)
nonAF_input[:,2]=np.amin(nonAF_data,axis=1)
nonAF_input[:,3]=np.amax(nonAF_data,axis=1)
nonAF_input[:,4]=np.ptp(nonAF_data,axis=1) #极差
nonAF_input[:,5]=np.std(nonAF_data,axis=1) #标准差
nonAF_input[:,6]=np.var(nonAF_data,axis=1) #方差
nonAF_input[:,7]=np.log(2*math.pi*math.e*np.var(nonAF_data,axis=1)) #
nonAF_input[:,8]=pd.DataFrame.skew(nonAF_data_frame,axis=1)
nonAF_input[:,9]=pd.DataFrame.kurt(nonAF_data_frame,axis=1)
print(nonAF_input.shape)

AF_label=np.ones(AF_input.shape[0])
nonAF_label=np.zeros(nonAF_input.shape[0])

print(AF_label.shape,nonAF_label.shape)

AF_input_frame=pd.DataFrame(AF_input)
nonAF_input_frame=pd.DataFrame(nonAF_input)
AF_label_frame=pd.DataFrame(AF_label)
nonAF_label_frame=pd.DataFrame(nonAF_label)

with pd.ExcelWriter('pre_treatment_data_feature_2.xlsx') as  f:
    AF_input_frame.to_excel(f,sheet_name='AF_input',header=False,index=False)
    nonAF_input_frame.to_excel(f,sheet_name='nonAF_input',header=False,index=False)
    AF_label_frame.to_excel(f,sheet_name='AF_label',header=False,index=False)
    nonAF_label_frame.to_excel(f,sheet_name='nonAF_label',header=False,index=False)

